package dk.nordahl.todolist;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;


public class ToDoListItemView extends TextView
{
	private Paint marginPaint;
	private Paint linePaint;
	private int paperColor;
	private float margin;

	public ToDoListItemView(Context context, AttributeSet ats, int ds)
	{
		super(context, ats, ds);
		Init();
	}
	public ToDoListItemView(Context context)
	{
		super(context);
	}
	public ToDoListItemView(Context context, AttributeSet ats)
	{
		super(context, ats);
	}
	
	private void Init()
	{
		Resources myResources = getResources();
		marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		marginPaint.setColor(myResources.getColor(R.color.notepad_margin));
		linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		linePaint.setColor(myResources.getColor(R.color.notepad_lines));
		
		paperColor = myResources.getColor(R.color.notepad_paper);
		margin = myResources.getDimension(R.dimen.notepad_margin);
	}
	@Override
	public void onDraw(Canvas canvas)
	{
		canvas.drawColor(paperColor);
		
		//Drawing rules
		canvas.drawLine(0, 0, 0, getMeasuredHeight(), linePaint);
		canvas.drawLine(0, getMeasuredHeight(),getMeasuredWidth(), getMeasuredHeight(),linePaint);
		
		//Draws margin
		canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginPaint);
		
		//Moves the text across from the margin
		canvas.save();
		canvas.translate(margin, 0);
		
		//Textview render text
		super.onDraw(canvas);
		canvas.restore();
	}
	
}
